package g4p.styledtext;

import processing.core.PApplet;
import g4p_controls.G4P;
import g4p_controls.GButton;
import g4p_controls.GEvent;
import g4p_controls.GTextArea;
import g4p_controls.GTextField;

public class TextSaveLoad_1 extends PApplet {

	GTextArea txa1, txa2;
	GTextField txf1;
	
	String startText;
	
	GButton btnTest1, btnTest2;
	String fn1 = "test1.txt";
	
	public void setup(){
		size(700,400);
		//Load some sample text
		String[] paragraphs = loadStrings("book3.txt");
		startText = PApplet.join(paragraphs, '\n');

		// Create a text area with both horizontal and 
		// vertical scrollbars that automatically hide 
		// when not needed.
		txa1 = new GTextArea(this, 20, 40, 280, 300, G4P.SCROLLBARS_BOTH ); //| G4P.SCROLLBARS_AUTOHIDE);
		txa1.setText(startText, 310);
		// Set some default text
		txa1.setPromptText("Please enter some text");

		txa2 = new GTextArea(this, 320, 40, 280, 300, G4P.SCROLLBARS_BOTH ); //| G4P.SCROLLBARS_AUTOHIDE);
		// Set some default text
		txa2.setPromptText("Please enter some text");

		
		txf1 = new GTextField(this, 10, 360, 680, 26, G4P.SCROLLBARS_HORIZONTAL_ONLY); // | G4P.SCROLLBARS_AUTOHIDE);

		btnTest1 = new GButton(this,20,10,80,20,"A > A");
		btnTest2 = new GButton(this,120,10,80,20,"A > F");
	}
	
	public void draw(){
		background(240);
	}
	
	
	public void handleButtonEvents(GButton button, GEvent event) { 
		if(button == btnTest1){
			txa1.saveText(fn1);
			txa2.loadText(fn1);
		}
		if(button == btnTest2){
			txa1.saveText(fn1);
			txf1.loadText(fn1);
		}
	}
}
